/**
 * @returns {import("./types").CurrencyConverterType}
 */
export function currencyConverterFactory() {
  return {
    currencies: ["USD", "EUR", "CNY"],
    usdToForeignRates: {
      USD: 1,
      EUR: 0.74,
      CNY: 6.09,
    },
    /**
     * @param {number} amount
     * @param {'USD' | 'EUR' | 'CNY'} inCurr
     * @param {'USD' | 'EUR' | 'CNY'} outCurr
     * @returns {number}
     */
    convert(amount, inCurr, outCurr) {
      return (
        (amount * this.usdToForeignRates[outCurr]) /
        this.usdToForeignRates[inCurr]
      );
    },
  };

  //  refresh = function () {
  //   var url =
  //     "https://api.exchangeratesapi.io/latest?base=USD&symbols=" +
  //     currencies.join(",");
  //   return $http.get(url).then(function (response) {
  //     usdToForeignRates = response.data.rates;
  //     usdToForeignRates["USD"] = 1;
  //   });
  // };

  //  refresh();
}
